//
//  MinePersonalDetailOccupationSchoolCell.swift
//  MT
//
//  Created by M on 2020/1/6.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MinePersonalDetailOccupationSchoolCell: UITableViewCell {

    var model: MineInfoModel? {
        didSet {
            guard let model = model else { return }
            occupationDetailLabel.text = model.industry ?? "-"
            positionDetailLabel.text = model.position ?? "-"
            schoolDetailLabel.text = model.school ?? "-"
            degreeDetailLabel.text = model.degree ?? "-"
        }
    }
    
    /// 身高 Title
    lazy var occupationTitleLabel: UILabel = {
        return createTitleLabel(text: "行业")
    }()
    
    /// 身高 Detail
    lazy var occupationDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    /// 体重 Title
    lazy var positionTitleLabel: UILabel = {
        return createTitleLabel(text: "职位")
    }()
    
    /// 身高 Detail
    lazy var positionDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    /// 星座 Title
    lazy var schoolTitleLabel: UILabel = {
        return createTitleLabel(text: "学校")
    }()
    
    /// 星座 Detail
    lazy var schoolDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    /// 星座 Title
    lazy var degreeTitleLabel: UILabel = {
        return createTitleLabel(text: "学位")
    }()
    
    /// 星座 Detail
    lazy var degreeDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initializeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

// MARK: ------------------------------------ 初始化 ----------------------------------------
extension MinePersonalDetailOccupationSchoolCell {
    
    private func initializeUI() {
        selectionStyle = .none
        contentView.backgroundColor = .black
        contentView.addSubview(occupationTitleLabel)
        contentView.addSubview(occupationDetailLabel)
        contentView.addSubview(positionTitleLabel)
        contentView.addSubview(positionDetailLabel)
        contentView.addSubview(schoolTitleLabel)
        contentView.addSubview(schoolDetailLabel)
        contentView.addSubview(degreeTitleLabel)
        contentView.addSubview(degreeDetailLabel)
        
        let titleWidth = 40.0
        
        occupationTitleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(contentView).offset(20)
            make.top.equalTo(contentView).offset(16)
            make.width.equalTo(titleWidth)
        }
        
        occupationDetailLabel.snp.makeConstraints { (make) in
            make.left.equalTo(occupationTitleLabel.snp.right).offset(8)
            make.bottom.equalTo(occupationTitleLabel)
            make.right.equalTo(contentView.snp.centerX)
        }
        
        schoolTitleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(occupationTitleLabel)
            make.top.equalTo(occupationTitleLabel.snp.bottom).offset(19)
            make.width.equalTo(titleWidth)
        }
        
        schoolDetailLabel.snp.makeConstraints { (make) in
            make.left.equalTo(schoolTitleLabel.snp.right).offset(8)
            make.bottom.equalTo(schoolTitleLabel)
            make.right.equalTo(occupationDetailLabel)
        }
        
        positionTitleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(contentView.snp.centerX).offset(6)
            make.bottom.equalTo(occupationTitleLabel)
            make.width.equalTo(titleWidth)
        }
        
        positionDetailLabel.snp.makeConstraints { (make) in
            make.left.equalTo(positionTitleLabel.snp.right).offset(8)
            make.bottom.equalTo(positionTitleLabel)
            make.right.equalTo(contentView).offset(-20)
        }
        
        degreeTitleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(positionTitleLabel)
            make.bottom.equalTo(schoolTitleLabel)
            make.width.equalTo(titleWidth)
        }
        
        degreeDetailLabel.snp.makeConstraints { (make) in
            make.left.equalTo(degreeTitleLabel.snp.right).offset(8)
            make.bottom.equalTo(degreeTitleLabel)
            make.right.equalTo(positionDetailLabel)
        }
    }
    
}

// MARK: ------------------------------------ 创建控件 ----------------------------------------
extension MinePersonalDetailOccupationSchoolCell {
    
    private func createTitleLabel(text: String) -> UILabel {
        let label = UILabel()
        label.text = text
        label.textColor = UIColor(hex: 0x5d5d5d)
        label.font = PingFangSCMediumFont(12)
        label.textAlignment = .left
        return label
    }
    
    private func createDetailLabel() -> UILabel {
        let label = UILabel()
        label.text = "-"
        label.textColor = .white
        label.font = PingFangSCMediumFont(14)
        label.textAlignment = .left
        return label
    }
    
}
